//
//  LXSignUpContractTableViewCell.m
//  ZuLinProject
//
//  Created by bancheng on 2022/3/22.
//  Copyright © 2022 LX_App. All rights reserved.
//

#import "LXSignUpContractTableViewCell.h"
@interface LXSignUpContractTableViewCell()
@end
@implementation LXSignUpContractTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    
    [self setBtnSpacing];
    
    self.carImage.userInteractionEnabled=YES;
    self.driverImage.userInteractionEnabled=YES;
    self.footImage.userInteractionEnabled=YES;
    [self.footImage addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(bigFoot)]];
    [self.driverImage addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(bigDriver)]];

    [self.carImage addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(bigCar)]];
    self.driverTipsLab.backgroundColor = [UIColor.blackColor colorWithAlphaComponent:0.8];
    [self.driverTipsLab addCorner:3];

    
}


-(void)setBtnSpacing{
    
    [self.contractHeadBtn setIconInTopWithSpacing:5];
    [self.contractFootBtn setIconInTopWithSpacing:5];
    [self.driverBtn setIconInTopWithSpacing:5];
    [self.carBtn setIconInTopWithSpacing:5];
    
    [self.headImage addCorner:3];
    [self.footImage addCorner:3];
    [self.driverImage addCorner:3];
    [self.carImage addCorner:3];
    
    
    [self.contractHeadBtn setCornerRadius:5];
    [self.contractFootBtn setCornerRadius:5];
    [self.driverBtn addCorner:5];
    [self.carBtn addCorner:5];
    
    self.headNumLab.backgroundColor = [UIColor.blackColor colorWithAlphaComponent:0.8];
    
    [self performSelector:@selector(setLine) withObject:nil afterDelay:0.1];

    
}
- (void)setLine{
    [self.headBackView setLineDashPattern:@[@4,@2] withColor:[UIColor colorWithHexString:@"#C4C4C4"] withCornerRadius:5];
    [self.footBackView setLineDashPattern:@[@4,@2] withColor:[UIColor colorWithHexString:@"#C4C4C4"] withCornerRadius:5];
    [self.carView setLineDashPattern:@[@4,@2] withColor:[UIColor colorWithHexString:@"#C4C4C4"] withCornerRadius:5];
    [self.driverView setLineDashPattern:@[@4,@2] withColor:[UIColor colorWithHexString:@"#C4C4C4"] withCornerRadius:5];

    
}

// 合同照片数据源
- (void)setContractData:(NSArray *)contractData{
    _contractData = contractData;
    if (!ObjectIsEmpty(contractData)) {
        self.headNumLab.hidden = NO;
        self.headNumLab.text = [NSString stringWithFormat:@"共%@张",@(self.contractData.count)];
        YLUploadMedia *media = contractData.firstObject;
        self.headImage.image = (UIImage *)media.obj;
        self.headImage.hidden = NO;
        self.contractHeadBtn.hidden = YES;

    }
    else {
        self.headNumLab.hidden = YES;
        self.headImage.hidden = YES;
        self.contractHeadBtn.hidden = NO;
    }
}


#pragma mark -- 上传合同照片
- (IBAction)clickHeadUpAction:(UIButton *)sender {
    
    if(self.contractData.count >= 10)return;
    [[LXPhotoHelper shareHelper] showImageViewSelcteWithResultBlock:^(id data) {
        [self uploadHead:data];
    } andMultipleImageBlock:^(id data) {
        [self uploadHead:data];
    } andSelectedNum:10 - self.contractData.count];
}
-(void)uploadHead:(NSArray *)data{
    if (self.contractAction) {
        self.contractAction(data);
    }
}
// MARK: 点击验车单上传
- (IBAction)clickFootUpAction:(UIButton *)sender {
    
    
    [[LXPhotoHelper shareHelper] showImageViewSelcteWithResultBlock:^(NSDictionary *dic) {
        self.checkCarUrl = [NSString stringWithFormat:@"%@",dic[@"url"]];
        if (self.clickAction) {
            self.clickAction(self.checkCarUrl,1);
        }
    }];
}
// 验车单
- (void)setCheckCarUrl:(NSString *)checkCarUrl{
    _checkCarUrl = checkCarUrl;
    if (!StringIsEmpty(checkCarUrl)) {
        self.footImage.hidden = NO;
        [self.footImage sd_setImageWithURL:[NSString URLStrEncoding:[NSString stringWithFormat:@"%@%@",HTTP_URL,checkCarUrl]]];
        self.footDelBtn.hidden = NO;
        self.contractFootBtn.hidden = YES;
    }
    else {
        self.footDelBtn.hidden = YES;
        self.footImage.hidden = YES;
        self.contractFootBtn.hidden = NO;
    }
    
}

// MARK: 上传行驶证
- (IBAction)upDriverImageAction:(UIButton *)sender {
    [[LXPhotoHelper shareHelper] showImageViewSelcteWithResultBlock:^(NSDictionary *dic) {
        self.driverUrl = [NSString stringWithFormat:@"%@",dic[@"url"]];
        if (self.clickAction) {
            self.clickAction(self.driverUrl,2);
        }
    }];
}
// 行驶证
- (void)setDriverUrl:(NSString *)driverUrl{
    _driverUrl = driverUrl;
    if (!StringIsEmpty(driverUrl)) {
        self.driverImage.hidden = NO;
        [self.driverImage sd_setImageWithURL:[NSString URLStrEncoding:[NSString stringWithFormat:@"%@%@",HTTP_URL,driverUrl]]];
        self.driverDelBtn.hidden = NO;
        self.driverBtn.hidden = YES;
    }
    else {
        self.driverDelBtn.hidden = YES;
        self.driverImage.hidden = YES;
        self.driverBtn.hidden = NO;
    }

    
    
}
// MARK: 上传车辆照片
- (IBAction)upCarImageAction:(UIButton *)sender {
    [[LXPhotoHelper shareHelper] showImageViewSelcteWithResultBlock:^(NSDictionary *dic) {
        self.carUrl = [NSString stringWithFormat:@"%@",dic[@"url"]];
        if (self.clickAction) {
            self.clickAction(self.carUrl,3);
        }
    }];
}
// 车辆照片
- (void)setCarUrl:(NSString *)carUrl{
    _carUrl = carUrl;
    if (!StringIsEmpty(carUrl)) {
        self.carImage.hidden = NO;
        [self.carImage sd_setImageWithURL:[NSString URLStrEncoding:[NSString stringWithFormat:@"%@%@",HTTP_URL,carUrl]]];
        self.carDelBtn.hidden = NO;
        self.carBtn.hidden = YES;
    }
    else {
        self.carDelBtn.hidden = YES;
        self.carImage.hidden = YES;
        self.carBtn.hidden = NO;
    }
    
}
#pragma mark -- 显示大图
-(void)showBigImage:(UIImage *)image{
    UIWindow *window = [BaseViewController getCurrentWindow];
    ShowBigImageWithFrameView *ImageShow = [[ShowBigImageWithFrameView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, B_HEIGHT) withImage:image];
    [window addSubview:ImageShow];
}
-(void)bigFoot{
    if (self.checkCarUrl) {
        [self showBigImage:self.footImage.image];
    }
}
-(void)bigCar{
    if (self.carUrl) {
        [self showBigImage:self.carImage.image];
    }
}
-(void)bigDriver{
    if (self.driverUrl && self.type != 3) {
        [self showBigImage:self.driverImage.image];
    }
}


@end
